<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var str = 'asdasdSMasdasdasdSMsdasdasdSMsadasd'
        //  先利用replace方法返回一个替换好的字符串
        var res = (str.replace('SM', '**'))
        //  循环字符串，置换所有的SM
        while (res.indexOf('SM') !== -1) {
            res = res.replace('SM', '**')
        }
        console.log(res)
    </script>
</body>

</html>